// ----------------------------------
// RSDK Project: S1f X DDLC
// Script Description: Music Override
// Script Author: Karl (only coder...)
// ----------------------------------

//-------Aliases-------//

// Function declarations
reserve function GHZSetup_DokiMixSpeedUp
reserve function GHZSetup_DokiMixSlowDown

reserve function MZ_DokiSpeedUp
reserve function MZ_DokiSlowDown

reserve function SYZ_DokiSpeedUp
reserve function SYZ_DokiSlowDown

reserve function LZ_DokiSpeedUp
reserve function LZ_DokiSlowDown

reserve function SLZSetup_FunctionSpeedUp
reserve function SLZSetup_FunctionSlowDown

reserve function SBZ_DokiSpeed
reserve function SBZ_DokiSlow


function GHZSetup_DokiMixSpeedUp
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("DokiMix/GreenHill_F.ogg", 0, 0x7AA16, 0x1EF0)
			break
		case 2
			SetMusicTrack("DokiMix/GreenHill_F.ogg", 0, 0x7AA16)
			SwapMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("DokiMix/GreenHill_F.ogg", 0, 0x7AA16)
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function GHZSetup_DokiMixSlowDown
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("DokiMix/GreenHill.ogg", 0, 0x9B0AA, 0x316A)
			break
		case 2
			SetMusicTrack("DokiMix/GreenHill.ogg", 0, 0x9B0AA)
			SwapMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("DokiMix/GreenHill.ogg", 0, 0x9B0AA)
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function

function MZ_DokiSpeedUp
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("DokiMix/Marble_F.ogg", 0, 71883, 0x1F40)
			break
		case 2
			SetMusicTrack("DokiMix/Marble_F.ogg", 0, 71883)
			SwapMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("DokiMix/Marble_F.ogg", 0, 71883)
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function MZ_DokiSlowDown
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("DokiMix/Marble.ogg", 0, 91951, 0x30D4)
			break
		case 2
			SetMusicTrack("DokiMix/Marble.ogg", 0, 91951)
			SwapMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("DokiMix/Marble.ogg", 0, 91951)
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			break
		end switch	
	else
		stage.musicFlag = 2
	end if
end function

function SYZ_DokiSpeedUp
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("DokiMix/SpringYard_F.ogg", 0, 0x13CE8, 0x1F40)
			break
		case 2
			SetMusicTrack("DokiMix/SpringYard_F.ogg", 0, 0x13CE8)
			SwapMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("DokiMix/SpringYard_F.ogg", 0, 0x13CE8)
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function SYZ_DokiSlowDown
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("DokiMix/SpringYard.ogg", 0, 0x18BF4, 0x30D4)
			break
		case 2
			SetMusicTrack("DokiMix/SpringYard.ogg", 0, 0x18BF4)
			SwapMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("DokiMix/SpringYard.ogg", 0, 0x18BF4)
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function

function LZ_DokiSpeedUp
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("DokiMix/Labyrinth_F.ogg", 0, 0x107D2, 0x1F40)
			break
		case 2
			SetMusicTrack("DokiMix/Labyrinth_F.ogg", 0, 0x107D2)
			SwapMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("DokiMix/Labyrinth_F.ogg", 0, 0x107D2)
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function LZ_DokiSlowDown
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("DokiMix/Labyrinth.ogg", 0, 0x149DC, 0x30D4)
			break
		case 2
			SetMusicTrack("DokiMix/Labyrinth.ogg", 0, 0x149DC)
			SwapMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("DokiMix/Labyrinth.ogg", 0, 0x149DC)
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function

function SLZSetup_FunctionSpeedUp
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("DokiMix/Starlight_F.ogg", 0, 50786, 0x1F40)
			break
		case 2
			SetMusicTrack("DokiMix/Starlight_F.ogg", 0, 50786)
			SwapMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("DokiMix/Starlight_F.ogg", 0, 50786)
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function SLZSetup_FunctionSlowDown
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("DokiMix/Starlight.ogg", 0, 63431, 0x30D4)
			break
		case 2
			SetMusicTrack("DokiMix/Starlight.ogg", 0, 63431)
			SwapMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("DokiMix/Starlight.ogg", 0, 63431)
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			break
		end switch
	else
		stage.musicFlag = 2
	end if
end function

function SBZ_DokiSpeed
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			SwapMusicTrack("DokiMix/ScrapBrain_F.ogg", 0, 1, 0x1F40)
			break
		case 2
			SetMusicTrack("DokiMix/ScrapBrain_F.ogg", 0, 1)
			SwapMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4, 0x1F40)
			break
		default
			SetMusicTrack("DokiMix/ScrapBrain_F.ogg", 0, 1)
			SetMusicTrack("DokiMix/Invincibility_F.ogg", 2, 0x76E4)
			break
		end switch
	else
		stage.musicFlag = 1
	end if
end function


function SBZ_DokiSlow
	CheckEqual(object[25].type, TypeName[Music Event])
	temp0 = checkResult
	CheckEqual(object[25].propertyValue, 2)
	temp0 &= checkResult
	CheckEqual(stage.musicFlag, 0)
	temp0 &= checkResult
	if temp0 == 0
		switch music.currentTrack
		case 0
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			SwapMusicTrack("DokiMix/ScrapBrain.ogg", 0, 1, 0x30D4)
			break
		case 2
			SetMusicTrack("DokiMix/ScrapBrain.ogg", 0, 1)
			SwapMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68, 0x30D4)
			break
		default
			SetMusicTrack("DokiMix/ScrapBrain.ogg", 0, 1)
			SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
			break			
		end switch
	else
		stage.musicFlag = 2
	end if
end function

event ObjectMain		
	SetMusicTrack("DokiMix/ActComplete.ogg", 1, 0)
	SetMusicTrack("DokiMix/Invincibility.ogg", 2, 0x9A68)
	SetMusicTrack("DokiMix/Continue.ogg", 3, 0)
	SetMusicTrack("DokiMix/Boss.ogg", 4, 393458)
	SetMusicTrack("DokiMix/GameOver.ogg", 5, 0)
	SetMusicTrack("DokiMix/Drowning.ogg", 6, 0)	
	switch saved.Supermusic
		case 1
			SetMusicTrack("DokiMix/Super.ogg", 7, 1)
			break
	end switch

	CheckCurrentStageFolder("Zone01")
	if checkResult == 1
		SetMusicTrack("DokiMix/GreenHill.ogg", 0, 0x9B0AA)
		SpeedUpMusic = GHZSetup_DokiMixSpeedUp
		SlowDownMusic = GHZSetup_DokiMixSlowDown
	end if
	CheckCurrentStageFolder("Zone02")
	if checkResult == 1
		SetMusicTrack("DokiMix/Marble.ogg", 0, 91951)
		SpeedUpMusic = MZ_DokiSpeedUp
		SlowDownMusic = MZ_DokiSlowDown
	end if
	CheckCurrentStageFolder("Zone03")
	if checkResult == 1
		SetMusicTrack("DokiMix/SpringYard.ogg", 0, 0x18BF4)
		SpeedUpMusic = SYZ_DokiSpeedUp
		SlowDownMusic = SYZ_DokiSlowDown
	end if
	CheckCurrentStageFolder("Zone04")
	if checkResult == 1
		if stage.actNum < 4	
			SetMusicTrack("DokiMix/Labyrinth.ogg", 0, 0x149DC)
			SpeedUpMusic = LZ_DokiSpeedUp
			SlowDownMusic = LZ_DokiSlowDown
		else
			SetMusicTrack("DokiMix/ScrapBrain.ogg", 0, 1)
			SpeedUpMusic = SBZ_DokiSpeed
			SlowDownMusic = SBZ_DokiSlow
		end if	
	end if
	CheckCurrentStageFolder("Zone05")
	if checkResult == 1
		SetMusicTrack("DokiMix/Starlight.ogg", 0, 63431)
		SpeedUpMusic = SLZSetup_FunctionSpeedUp
		SlowDownMusic = SLZSetup_FunctionSlowDown
	end if
	CheckCurrentStageFolder("Zone06")
	if checkResult == 1
		if stage.actNum < 5
			SetMusicTrack("DokiMix/ScrapBrain.ogg", 0, 1)
			SpeedUpMusic = SBZ_DokiSpeed
			SlowDownMusic = SBZ_DokiSlow
		else
			SetMusicTrack("DokiMix/Final.ogg", 0, 0x14AC8)
		end if
	end if

	CheckCurrentStageFolder("Continue")
	if checkResult == 1
		SetMusicTrack("DokiMix/Continue.ogg", 0, 0)
	end if

	PleaseReplaceLifeSoundEffect = 1

	object.type = TypeName[Blank Object]
end event


event ObjectStartup
	switch saved.dokiTracks
	case 0
		temp0 = 0
		break
	case 1
		temp0 = 1
		break
	case 2
		CheckGreater(stage.playerListPos, 5)
		temp0 = checkResult
		break
	end switch
	if temp0 == 1
		CreateTempObject(TypeName[Music Override], 0, 0, 0)
		object[tempObjectPos].priority = PRIORITY_ACTIVE_PAUSED
	end if	
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
